Иногда нужно выполнить блок кода с несколькими менеджерами контекста:
with open('f') as f: with open('g') as g: with open('h') as h: pass
Начиная с Python 2.7 и 3.1, это можно записать в одной конструкции with:
o = open with o('f') as f, o('g') as g, o('h') as h: pass
Раньше для этого использовали функцию contextlib.nested:
with nested(o('f'), o('g'), o('h')) as (f, g, h): pass
Если же число менеджеров контекста заранее неизвестно, лучше подойдёт более продвинутый инструмент. contextlib.ExitStack позволяет открывать любое число контекстов в произвольный момент, но гарантирует корректный выход из них в конце:
with ExitStack() as stack: f = stack.enter_context(o('f')) g = stack.enter_context(o('g')) other = [ stack.enter_context(o(filename)) for filename in filenames ]
Иногда нужно выполнить блок кода с несколькими менеджерами контекста:
with open('f') as f: with open('g') as g: with open('h') as h: pass
Начиная с Python 2.7 и 3.1, это можно записать в одной конструкции with:
o = open with o('f') as f, o('g') as g, o('h') as h: pass
Раньше для этого использовали функцию contextlib.nested:
with nested(o('f'), o('g'), o('h')) as (f, g, h): pass
Если же число менеджеров контекста заранее неизвестно, лучше подойдёт более продвинутый инструмент. contextlib.ExitStack позволяет открывать любое число контекстов в произвольный момент, но гарантирует корректный выход из них в конце:
with ExitStack() as stack: f = stack.enter_context(o('f')) g = stack.enter_context(o('g')) other = [ stack.enter_context(o(filename)) for filename in filenames ]
Launched in 2013, Telegram allows users to broadcast messages to a following via “channels”, or create public and private groups that are simple for others to access. Users can also send and receive large data files, including text and zip files, directly via the app.The platform said it has more than 500m active users, and topped 1bn downloads in August, according to data from SensorTower.
Telegram has exploded as a hub for cybercriminals looking to buy, sell and share stolen data and hacking tools, new research shows, as the messaging app emerges as an alternative to the dark web.An investigation by cyber intelligence group Cyberint, together with the Financial Times, found a ballooning network of hackers sharing data leaks on the popular messaging platform, sometimes in channels with tens of thousands of subscribers, lured by its ease of use and light-touch moderation.Библиотека Python разработчика from es